package com.frxuexi.lib_base.http

import com.frxuexi.lib_base.entity.KeyBean
import com.frxuexi.lib_base.entity.NewsBean
import com.frxuexi.lib_base.entity.NewsBeanItem
import com.frxuexi.lib_base.entity.NoticeBean
import com.frxuexi.lib_base.entity.NoticeBeanItem
import com.frxuexi.lib_base.entity.ParkBean
import com.frxuexi.lib_base.entity.ParkBeanItem
import com.frxuexi.lib_base.entity.RepairBean
import com.frxuexi.lib_base.entity.RepairBeanItem
import com.frxuexi.lib_base.entity.Res
import com.frxuexi.lib_base.entity.SignBean
import com.frxuexi.lib_base.entity.SignBeanItem
import com.frxuexi.lib_base.entity.TaskBean
import com.frxuexi.lib_base.entity.UserBean
import com.frxuexi.lib_base.entity.VisitBean
import com.frxuexi.lib_base.entity.VisitBeanItem
import kotlinx.coroutines.flow.Flow
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.Multipart
import retrofit2.http.PATCH
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Part
import retrofit2.http.Path
import retrofit2.http.Query

interface ApiService {
    @GET("/api/news")
    fun getNews():Flow<Res<NewsBean>>

    @POST("/api/user/login")
    fun login(@Query("username")username:String,@Query("password")pass:String):Flow<Res<UserBean>>


    @GET("/api/dictionaries?page=0&size=20")
    fun getKeys():Flow<Res<KeyBean>>

    @Multipart
    @POST("/api/file/upload")
    fun upload(@Part list: List<MultipartBody.Part> ,@Query("modulename")modulename:String,@Query("userid")userid:String):Flow<Res<String>>

    //车位
    @GET("/api/parking-spaces/type/{spaceType}")
    fun getParksByType(@Path("spaceType")spaceType:String):Flow<Res<ParkBean>>

    @DELETE("/api/parking-spaces/{id}")
    fun deletePark(@Path("id")id:Int):Flow<Res<Boolean>>

    @GET("/api/parking-spaces/status/{spaceStatus}")
    fun getParksByStatus(@Path("spaceStatus")spaceStatus:String):Flow<Res<ParkBean>>

    @GET("/api/parking-spaces/area/{areaId}")
    fun getParksByArea(@Path("areaId")areaId:Int):Flow<Res<ParkBean>>


    @POST("/api/parking-spaces")
    fun addPark(@Body body: RequestBody):Flow<Res<ParkBeanItem>>

    @GET("/api/parking-spaces/{id}")
    fun getParkById(@Path("id")id:Int):Flow<Res<ParkBeanItem>>

    @PUT("/api/parking-spaces/{id}")
    fun updatePark(@Path("id")id:Int,@Body body: RequestBody):Flow<Res<ParkBeanItem>>

    @PATCH("/api/parking-spaces/{id}/status")
    fun approvePark(@Path("id")id:Int,@Query("status")status:String):Flow<Res<ParkBeanItem>>

    //维修
    @GET("/api/repair-orders")
    fun getRepairs():Flow<Res<RepairBean>>

    @GET("/api/repair-orders/order-number/{orderNumber}")
    fun getRepairByNum(@Path("orderNumber")orderNumber:String):Flow<Res<RepairBeanItem>>

    @GET("/api/repair-orders/search")
    fun getRepairsByUname(@Query("repairName")repairName:String):Flow<Res<RepairBean>>

    @DELETE("/api/repair-orders/{id}")
    fun deleteRepair(@Path("id")id:Int):Flow<Res<Boolean>>

    @POST("/api/repair-orders")
    fun addRepair(@Body body: RequestBody):Flow<Res<RepairBeanItem>>

    @GET("/api/repair-orders/{id}")
    fun getRepairById(@Path("id")id:Int):Flow<Res<RepairBeanItem>>

    @PUT("/api/repair-orders/{id}")
    fun updateRepair(@Path("id")id:Int,@Body body: RequestBody):Flow<Res<RepairBeanItem>>


    //预约来访
    @GET("/api/visit-appointments")
    fun getVisits():Flow<Res<VisitBean>>

    @GET("/api/visit-appointments/status/{status}")
    fun getVisitByStatus(@Path("status")status:String):Flow<Res<VisitBean>>

    @GET("/api/visit-appointments/search/name")
    fun getVisitByName(@Query("name")name:String):Flow<Res<VisitBean>>

    @GET("/api/visit-appointments/search/purpose")
    fun getVisitByPurpose(@Query("purpose")purpose:String):Flow<Res<VisitBean>>

    @DELETE("/api/visit-appointments/{id}")
    fun deleteVisit(@Path("id")id:Int):Flow<Res<Boolean>>

    @POST("/api/visit-appointments")
    fun addVisit(@Body body: RequestBody):Flow<Res<VisitBeanItem>>

    @GET("/api/visit-appointments/{id}")
    fun getVisitById(@Path("id")id:Int):Flow<Res<VisitBeanItem>>

    @PATCH("/api/visit-appointments/approve/{id}")
    fun approveVisit(@Path("id")id: Int):Flow<Res<VisitBeanItem>>

    @PATCH("/api/visit-appointments/reject/{id}")
    fun rejectVisit(@Path("id")id: Int):Flow<Res<VisitBeanItem>>


    //公告
    @GET("/api/announcements?size=10")
    fun getNotices(@Query("page")page:Int):Flow<Res<NoticeBean>>

    @POST("/api/announcements")
    fun addNotice(@Body body: RequestBody):Flow<Res<NoticeBeanItem>>

    @GET("/api/announcements/{id}")
    fun getNoticeById(@Path("id")id: Int):Flow<Res<NoticeBeanItem>>

    //文化新闻
    @PATCH("/api/news/revoke/{id}")
    fun revokeNews(@Path("id")id:Int):Flow<Res<Boolean>>

    @GET("/api/news/search")
    fun getNewsByKey(@Query("keyword")keyword:String):Flow<Res<NewsBean>>

    @DELETE("/api/news/{id}")
    fun deleteNews(@Path("id")id:Int):Flow<Res<Boolean>>

    @POST("/api/news")
    fun addNews(@Body body: RequestBody):Flow<Res<NewsBeanItem>>

    @GET("/api/news/{id}")
    fun getNewsById(@Path("id")id:Int):Flow<Res<NewsBeanItem>>

    @PUT("/api/news/{id}")
    fun updateNews(@Path("id")id:Int,@Body body: RequestBody):Flow<Res<NewsBeanItem>>

    @GET("/api/attendances/user/{userId}")
    fun getrSigns(@Path("userId")userId:Int):Flow<Res<SignBean>>

    @POST("/api/attendances")
    fun sign(@Body body: RequestBody):Flow<Res<SignBeanItem>>

    @GET("/api/patrol-tasks/by-person/{personId}")
    fun getMyTasks(@Path("personId")personId:Int):Flow<Res<TaskBean>>
}